<?php
/**
 * Created by PhpStorm.
 * User: mr.lee
 * Date: 2018/10/18
 * Time: 4:20 PM
 */

namespace app\notify\controller;

use app\common\controller\ActionLogs;
use app\common\controller\Pub;
use app\common\model\Huifu;
use app\common\model\HuifuLog;
use app\common\model\Paylog;
use app\index\controller\Huifupay;
use think\Controller;

class Notify extends Controller
{
    public function huifu_mach_join()
    {


        $postStr = request()->param();
        if (!empty($postStr)) {
            //微信支付事件接收
            $ActionLogs = new ActionLogs();
            $ActionLogs->writelog("payos", "notify", "event/huifu_mach_join", "接收推送信息:", $postStr);
            $res = json_decode($postStr['jsonData'], true);
            if ($res['businessStat'] == 0) {
                $data['status'] = 99;
            } elseif ($res['businessStat'] == 1) {
                $data['status'] = 3;
                $data['merchid']=$res['memberId'];
            }
            $map['reqSerialNum'] = $res['reqSerialNum'];
            $HuifuLog=new HuifuLog();
            $hid=$HuifuLog->where($map)->value('hid');
            if($hid){
                $map1['id']=$hid;
                $Huifu = new Huifu();
                $data['status'] = 3;
                $Huifu->save($data, $map1);
            }


        }


    }

    public function paynotice()
    {
        $postStr = request()->param();
//        file_put_contents('/data2/html/payos/00ooo000.log', json_encode($postStr), 8);

        if ($postStr) {
            if ($postStr['respCode'] == "000000") {
                $Paylog = new Paylog();
                if ($postStr['transStat'] == "S") {
                    $Huifupay = new Huifupay();
                    $Huifupay->order_query($postStr['termOrdId']);
                }
                $payinfo = $Paylog->where(['orderid' => $postStr['termOrdId']])->field('tzzt,mid')->find();
                if ($payinfo['tzzt'] == '0') {
                    $Pub = new Pub();
                    $Pub->sendnotify($payinfo['mid'], $postStr);
                } elseif ($payinfo['tzzt'] == 1) {
                    return "NO_RECV_ORD_ID_" . $postStr['ordId'];
                }

            }
        }
    }

    public function huifu_mach_modify()
    {


        $postStr = request()->param();
        if (!empty($postStr)) {
            //微信支付事件接收
            $ActionLogs = new ActionLogs();
            $ActionLogs->writelog("payos", "notify", "event/huifu_mach_modify", "接收推送信息:", $postStr);

        }
    }

    public function huifu_jiesuan_modify()
    {


        $postStr = request()->param();
        if (!empty($postStr)) {
            //微信支付事件接收
            $ActionLogs = new ActionLogs();
            $ActionLogs->writelog("payos", "notify", "event/huifu_jiesuan_modify", "接收推送信息:", $postStr);

        }
    }

    public function huifu_wxmp_modify()
    {
        $postStr = request()->param();
        if (!empty($postStr)) {
            //微信支付事件接收
            $ActionLogs = new ActionLogs();
            $ActionLogs->writelog("payos", "notify", "event/huifu_wxmp_modify", "接收推送信息:", $postStr);

        }
    }

}